#include <stdio.h>
#include <stdlib.h>

void hex_bin(int n);

int main(int argc, char *argv[]) {
	test_show_bytes();
	return 0;
}
typedef unsigned char *byte_pointer;

void test_show_bytes() {
	float fval = 5322;
	int ival = fval;

	//printf("%d\n",ival);
	//printf("%f\n",fval);

	show_bytes((byte_pointer)&ival,sizeof(int));
	show_bytes((byte_pointer)&fval,sizeof(float));
	
	//float fval = 53.22;
	//int *pval = &ival;
	//show_int(ival);
	//show_float(fval);
	//show_pointer(pval);
}

void show_bytes(byte_pointer start, size_t len) {
	//printf("3-%s\n",start);	
	size_t i,j;
	for (i = 0; i < len; i++){
		printf("              ");
		printf("%.2x", start[i]);
		printf(" "); 
	} 

	printf("\n");
	for (i = 0; i < len; i++){
		 hex_bin(start[i]);
		
	} 
	printf("\n");
	
/*
	for(i = 0; i < len; i++) {
		temp = start[i];
		//printf(" %.2x", temp);
		if(temp == 0) {
			for(j = i*8; j < 2*len; j++){
		
			a[2*len-1-j] = temp % 2;
			temp /= 2;
			}
			i++;
			for(j = i*8; j < 2*len; j++){
		
			a[2*len-1-j] = temp % 2;
			temp /= 2;
			}
		}
		else {
			for(j = i*8; j < 2*len; j++){
		
				a[2*len-1-j] = temp % 2;
				temp /= 2;
			}
		}
	}
	for(j = 0; j < 8*len; j++){
                printf("%d",a[j]);
		if((j+1)%4 == 0 && j!=0) printf(" ");
        }
	printf("\n");
	*/
}

void show_int(int x) {
	//printf("1-%s\n",(byte_pointer)&x);
	show_bytes((byte_pointer) &x, sizeof(int));
}

void show_float(float x) {
	printf("2-%s\n",(byte_pointer)&x);
	show_bytes((byte_pointer) &x, sizeof(float));
}

void show_pointer(void *x) {
	show_bytes((byte_pointer) &x, sizeof(void *));
}

void hex_bin(int n) {
    int a[16];
    int i;
    for (i = 0; i != 16; ++i)
    {
        a[16 - 1 - i] = n % 2;
        n /= 2;
    }
    for (i = 0; i != 16; ++i)
    {
        printf("%d",a[i]);
        if((i+1)%4 == 0)
            printf("");
    }
    printf(" ");
}
